package pe.gob.onpe.ctrlInterface;

import javax.mail.*;
import javax.mail.internet.*;
import pe.gob.onpe.util.PARAMETROS;
import java.util.*;
	
public class EnvioCorreo{

	public void envioCorreo(String emailDestino,String tituloCorreo, String contenidoCorreo, String tipoCorreo){
		
		try {
			Properties props = new Properties();
	
			String host		= PARAMETROS.MAIL_SERVIDOR;
			String to		= emailDestino;
			String from		= PARAMETROS.MAIL_ENVIADOR_CORREO;
			String clave	= PARAMETROS.MAIL_ENVIADOR_CONTRASENA;
			int puerto		= PARAMETROS.MAIL_SERVIDOR_PUERTO;		//465;
			/*	String host	= "smtp.1and1.com";
				String to	= "ventas@warperu.com";
				String from	= "ventas@warperu.com";
				String clave= "omarcito";
				int puerto = 25; */
	        props.put("mail.transport.protocol", PARAMETROS.MAIL_PROTOCOLO);
			//props.put("mail.transport.protocol", "smtp");
	        props.put("mail.smtps.host", host);
	        props.put("mail.smtps.auth", "true");
	    
	        Session mailSession = Session.getDefaultInstance(props);
	        mailSession.setDebug(true);
	        Transport transport = mailSession.getTransport();
	
	        MimeMessage message = new MimeMessage(mailSession);
	        message.setSubject(tituloCorreo);
	        message.setContent(contenidoCorreo, tipoCorreo);
	        Address a = new InternetAddress(from);
	        message.setFrom(a);
	        
	        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
	
	        transport.connect(host, puerto, from, clave);
	
	        transport.sendMessage(message,
	        message.getRecipients(Message.RecipientType.TO));
	        transport.close();
	
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}